package validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator("UserEmailValidator")
public class UserEmailValidator implements Validator{

	@Override
	public void validate(FacesContext arg0, UIComponent arg1, Object arg2)
			throws ValidatorException {
		String value=arg2.toString();
		if(!value.matches("^[A-Z-a-z0-9.-]+@[a-z.]+.[a-z]{2,6}$")){
			throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN,"Format de mail incorrect","Format de mail incorrect"));
		}
		
	}

}
